﻿using System;
using System.Globalization;
using System.Threading;
using System.Web;
using System.Web.UI;

namespace Medianamik.Client.MVP.View
{
    public class BasePage : Page
    {
        protected override void InitializeCulture()
        {
            base.InitializeCulture();
            var rewritedUrlCultureName = HttpContext.Current.Items["RewritedUrlCultureName"] as string;
            
            if (rewritedUrlCultureName != null)
            {
               Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(rewritedUrlCultureName);
               Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo(rewritedUrlCultureName);
            }
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            var u = HttpContext.Current.Items["Medianamik-Rewrite-Url"];
            
            if (Form != null && u != null && u.ToString().Length > 0)
            {
                Form.Action = u + Request.Url.Query;
            }
        }
    }
}
